<include file="Public/header"/>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadimg/webuploader.css">
<!--<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadimg/style.css">-->
<div class="wrapper m-t">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <a class="h5 font-bold">
                <if condition="$re neq null">
                    新增<else/>编辑
                </if>


                图文回复</a>
        </div>
        <div class="ibox-content">
            <form class="form-horizontal form-imagetext" method="post" action="{:U()}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">回复规则名称</label>

                    <div class="col-sm-6">
                        <input type="text" value="<if condition='$re.msg_name neq null'>{$re.msg_name}</if>"
                               placeholder="请输入回复规则名称" name="msg_name" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（您可以给这条规则起一个名字, 方便下次修改和查看）</span>
                    </div>
                </div>
                <div class="line line-dashed line-lg pull-in"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">触发关键字</label>

                    <div class="col-sm-6">
                        <input type="text" value="<if condition='$re.keyword neq null'>{$re.keyword}</if>"
                               placeholder="请输入触发关键词" name="keyword" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（当用户的对话内容符合以上的关键字定义时，会触发这个回复定义）</span>
                    </div>
                </div>
                <div class="line line-dashed line-lg pull-in"></div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">图文标题</label>

                    <div class="col-sm-6">
                        <input type="text" value="<if condition='$re.title neq null'>{$re.title}</if>"
                               placeholder="请输入图文标题" name="title" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（图文消息标题）</span>
                    </div>
                </div>
                <div class="line line-dashed line-lg pull-in"></div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">图文描述</label>

                    <div class="col-sm-6">
                        <textarea class="form-control" placeholder="请输入图文消息描述" name="msg_desc" rows="3"><if
                                condition='$re.msg_desc neq null'>{$re.msg_desc}
                        </if></textarea>
                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（图文消息描述）</span>
                    </div>
                </div>
                <div class="line line-dashed line-lg pull-in"></div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">图文链接地址</label>

                    <div class="col-sm-6">
                        <input type="text" value="<if condition='$re.msg_link neq null'>{$re.msg_link}</if>"
                               placeholder="请输入链接地址" name="msg_link" class="form-control">
                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（点击图文跳转的链接地址）</span>
                    </div>
                </div>
                <div class="line line-dashed line-lg pull-in"></div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">封面图片地址</label>

                    <div class="col-sm-6">
                        <input class="form-control m-b" placeholder="上传图片或输入图片地址" type="text" name="img_msg" value="{$re.img_msg}"/>
                        <div id="uploader-demo">
                            <!--用来存放item-->
                            <div id="fileList" class="uploader-list"></div>
                            <div id="filePicker">选择图片</div>

                        </div>

                    </div>
                    <div class="col-sm-4">
                        <span class="help-block m-b-none">（图文消息封面图片）</span>
                    </div>
                </div>

                <div class="line line-dashed line-lg pull-in"></div>


                <div class="form-group">
                    <label class="col-sm-2 control-label">状态</label>

                    <div class="col-sm-6">
                        <notempty name="re">
                            <if condition="$re.status eq 1">
                                <input type="radio" value="1" name="status" checked>启用&nbsp;&nbsp;&nbsp;
                                <input type="radio" value="0" name="status">禁用
                                <else/>
                                <input type="radio" value="1" name="status">启用&nbsp;&nbsp;&nbsp;
                                <input type="radio" value="0" name="status" checked>禁用
                            </if>
                            <input type="hidden" name="kid" value="{$re.kid}"/>
                        </notempty>
                        <empty name="re">
                            <input type="radio" value="1" name="status" checked>启用&nbsp;&nbsp;&nbsp;
                            <input type="radio" value="0" name="status">禁用
                        </empty>


                    </div>

                </div>
                <div class="line line-dashed line-lg pull-in"></div>


                <div class="form-group">
                    <div class="col-sm-6 col-sm-offset-2">
                        <button type="submit" class="btn col-lg-2 m-r btn-info ajax-post " target-form="form-imagetext">
                            确定
                        </button>
                        <button type="button" onclick="javascript:history.back(-1);return false;"
                                class="btn col-lg-2 m-r btn-primary">返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<include file="Public/footer"/>
<script type="text/javascript" src="__PUBLIC__/uploadimg/webuploader.js"></script>
<!--<script src="__PUBLIC__/uploadimg/uploadImg.js"></script>-->
<script>

    // 图片上传demo
    jQuery(function() {
        var $ = jQuery,
                $list = $('#fileList'),
        // 优化retina, 在retina下这个值是2
                ratio = window.devicePixelRatio || 1,

        // 缩略图大小
                thumbnailWidth = 100,
                thumbnailHeight = 100,

        // Web Uploader实例
                uploader;

        // 初始化Web Uploader
        uploader = WebUploader.create({

            // 自动上传。
            auto: true,

            // swf文件路径
            swf: '__PUBLIC__' + '/uploadimg/Uploader.swf',

            // 文件接收服务端。
            server:"{:U('Mobile/ClientServer/orderCommit')}" ,

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker',
            //上传数量
            fileNumLimit: 3,

            // 只允许选择文件，可选。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });





        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                            '<div id="' + file.id + '" class="file-item ">' +
                            '<img>' +
                            '</div>'
                    ),
                    $img = $li.find('img');

            $list.append( $li );

            // 创建缩略图
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, thumbnailWidth, thumbnailHeight );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {

            var $li = $( '#'+file.id ),
                    $percent = $li.find('.progress span');
//
            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                        .appendTo( $li )
                        .find('span');
            }

            $percent.css( 'width', percentage * 100 + '%' );
        });

        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,data ) {
            $( '#'+file.id ).addClass('upload-state-done');
            if(data.state=='success'){

                $("[name='img_msg']").val(data.info);


            }
        });

        // 文件上传失败，现实上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                    $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });
</script>